package com.bird.thread.base.background;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: bird
 * @Data: 2021/7/5 17:02
 * @description: 验证：构造函数中使用子线程初始化造成的线程安全问题.
 *
 */
public class ConstructThread {

    private Map<String, String> states;

    public ConstructThread() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                states = new HashMap<>();
                states.put("1", "周一");
                states.put("2", "周二");
                states.put("3", "周三");
                states.put("4", "周四");
            }
        }).start();
    }

    public Map<String, String> getStates() {
        return states;
    }



    public static void main(String[] args) throws InterruptedException {
        ConstructThread multiThreadsError6 = new ConstructThread();
        //Thread.sleep(1000);
        System.out.println(multiThreadsError6.getStates().get("1"));
    }

}
